﻿using System;
using System.Web.Services;
using Monkey.Warrenty.Biz;
using Monkey.Warrenty.Constants;
using MonkeyWarranty.Models.TicketModels;
using MonkeyWarranty.Web.Common;

namespace MonkeyWarranty.Web.InstantTickets
{
    public partial class Products : System.Web.UI.Page
    {
        #region Properties

        private static InstantTicketBiz _instantTicketBiz;
        private static InstantTicketBiz InstantTicketManager
        {
            get { return _instantTicketBiz ?? (_instantTicketBiz = new InstantTicketBiz()); }
        }

        #endregion
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (WarrantyCommon.CurrrentEmployee == null)
            {
                Response.Redirect("~/Logon.aspx");
                return;
            }

            if (!WarrantyCommon.CurrrentEmployee.HasRole(RoleConstant.AdminDichVu))
            {
                Response.Redirect("~/NoPermission.aspx");
            }
        }

        [WebMethod(EnableSession = true)]
        public static object ProductList(int jtStartIndex, int jtPageSize, string jtSorting, InstantProductSearchModel search)
        {
            search.StartIndex = jtStartIndex;
            search.PageSize = jtPageSize;
            search.Sorting = jtSorting;

            var count = InstantTicketManager.SearchProductsCount(search);
            var ticketProducts = InstantTicketManager.SearchProducts(search);

            return new { Result = "OK", Records = ticketProducts, TotalRecordCount = count };
        }
    }
}